/*
 * @Author: YinJianFeng 814922893@qq.com
 * @Date: 2025-01-23 18:13:47
 * @LastEditors: YinJianFeng 814922893@qq.com
 * @LastEditTime: 2025-01-23 18:21:25
 */

import { BaseCommand, Icon, log } from '@amcax/base';
import { Button, Tooltip } from 'antd';
import i18n from 'i18next';
import { useEffect, useState } from 'react';
import styles from './styles.module.scss';
interface IProps {
  cmd: BaseCommand;
}

export default function TopButton({ cmd }: IProps) {
  useEffect(() => {
    log('CmdButton Init', cmd);
    cmd.subscribeDisabled?.(setDisabled);
  }, []);
  const [disabled, setDisabled] = useState(!!cmd.initialDisabled);

  return (
    <Tooltip
      title={cmd.label ? i18n.t(cmd.label) : undefined}
      placement='bottom'>
      <Button
        className={styles.TopButton}
        disabled={disabled}
        icon={
          cmd.icon && (
            <Icon
              name={cmd.icon}
              style={{
                fontSize: '24px',
                opacity: disabled ? 0.3 : 1,
              }}
            />
          )
        }></Button>
    </Tooltip>
  );
}
